package com.mp.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
public class MyBatisPlusConfiguration {

//    @Bean
//    public ISqlInjector sqlInjector(){
//        return new LogicSqlInjector();
//    }


    //配置乐观锁插件
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }

    @Bean
    @Profile({"dev", "test"})
    public PerformanceInterceptor performanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        //如果要格式化SQL查询语句，就要setFormat(true)
        performanceInterceptor.setFormat(true);
//        设置SQL语句最长运行时间，如果超过5ms，就停止
//        performanceInterceptor.setMaxTime(5L);

        return performanceInterceptor;
    }
}
